package cn.edu.ctbu.lddweb.controller;

import cn.edu.ctbu.lddweb.pojo.Student;
import cn.edu.ctbu.lddweb.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * 个人信息（学生）
 */
@Controller
public class Pserson_SController {

    @Autowired
    private StudentService studentService;

    //个人中心
    @RequestMapping("/person/edit1")
    public String edit1(Model model, String username, ModelMap map,Student student) {
       student.setUsername(username);
        List<Student> list = studentService.selectList(student);
        if (list.size() != 0) {
            map.put("id",list.get(0).getId());
            map.put("username",list.get(0).getUsername());
            map.put("pwd",list.get(0).getPwd());
            map.put("sex",list.get(0).getSex());
            map.put("className",list.get(0).getClassName());
            map.put("gradeName",list.get(0).getGradeName());
        }
        return "/person/edit1";
    }

    //修改操作（学生）
    @RequestMapping("/updatePerson1")
    public String updateGrade1(Model model, String username, ModelMap map, Student student) {
        studentService.updatePerson(student);
        List<Student> list = studentService.selectList(student);
        map.put("id",list.get(0).getId());
        map.put("username",list.get(0).getUsername());
        map.put("pwd",list.get(0).getPwd());
        map.put("sex",list.get(0).getSex());
        map.put("className",list.get(0).getClassName());
        map.put("gradeName",list.get(0).getGradeName());
        return "/person/edit1";
    }
}
